package ncme.auto.framework.core.exceptions;

public class AutoException extends RuntimeException {

    private Integer code;

    private String message;

    public AutoException() {
        super("未知服务器错误");
        this.code = 1001;
        this.message = "未知服务器错误";
    }

    public AutoException(String message) {
        super(message);
        this.code = 1001;
        this.message = message;
    }

    public AutoException(String message, Exception e) {
        super(message + "。 caused by: " + e.getMessage());
        this.code = 1001;
        this.message = message + "。 caused by: " + e.getMessage();
    }

    public AutoException(ExceptionEnum exceptionEnum) {
        super(exceptionEnum.getMsg());
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMsg();
    }

    public AutoException(ExceptionEnum exceptionEnum, String message) {
        super(exceptionEnum.getMsg() + "，由于：" + message);
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMsg() + "，由于：" + message;
    }

    public AutoException(ExceptionEnum exceptionEnum, Exception e) {
        super(exceptionEnum.getMsg() + "，由于：" + e.getMessage());
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMsg() + "，由于：" + e.getMessage();
    }

    public AutoException(ExceptionEnum exceptionEnum, String message, Exception e) {
        super(exceptionEnum.getMsg() + "，由于：" + message + "。 caused by: " + e.getMessage());
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMsg() + "，由于：" + message + "。 caused by: " + e.getMessage();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "BaseCustomException{" + "code=" + code + ", message='" + message + '\'' + '}';
    }
}
